package com.gexiaobao.pigeon.ui.adapter

import android.graphics.Color
import android.text.util.Linkify
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.LogisticsProgressResponse
import com.gexiaobao.pigeon.databinding.LayoutLogisticsTimeLineBinding
import java.util.regex.Pattern

/**
 * @Author      : hxw
 * @Date        : 2023/7/10 16:06
 * @Describe    :
 */
class LogisticsProgressAdapter(data: ArrayList<LogisticsProgressResponse.ListData>) :
    BaseQuickAdapter<LogisticsProgressResponse.ListData, DataBindBaseViewHolder>(R.layout.layout_logistics_time_line, data) {//item_logistics_progress

    override fun convert(holder: DataBindBaseViewHolder, item: LogisticsProgressResponse.ListData) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as LayoutLogisticsTimeLineBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        /** 设置手机号超链接 */
        val tvInfo = holder.getView<AppCompatTextView>(R.id.tvItemLogisticsProgress)
        val pattern: Pattern = Pattern.compile("(0\\d{2}-\\d{8}(-\\d{1,4})?)|(0\\d{3}-\\d{7,8}(-\\d{1,4})?)|\\d{11}")
        Linkify.addLinks(tvInfo, pattern, "tel:")
        /** 修改超文本链接的字体颜色 */
        tvInfo.setLinkTextColor(Color.parseColor("#4FBBFF"))

        val circleView = holder.getView<AppCompatImageView>(R.id.circleView)
        if (holder.layoutPosition == 1) {
            circleView.setImageResource(R.mipmap.icon_logic_finish)
        } else {
            circleView.setImageResource(R.mipmap.icon_logic_default_status)
        }
    }
}